#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cctype>
#include <array>
#include <vector>

using namespace std;

void exe_1();
void exe_2();
void exe_3();
void exe_4();
void exe_5();
void exe_6();
void exe_7();
void exe_8();
void exe_9();

int main(){
    exe_9();
    return 0;
}

void exe_1(){
    char ch;

    while ((ch = cin.get()) != '@'){
        if(isalpha(ch)){
            ch = tolower(ch);
            cout << ch << " ";
        }
    }

}

void exe_2(){
    const int MAX = 10;
    array<double, MAX> don {0.0};

    double sum(0.0);
    int i(1);
    int mount(0);

    /*for(i = 0; i < MAX; i++){
      cout << "Donut#" << i+1 << " ";
      while (!(cin >> don[i])){
      cin.clear();
      while (cin.get() != '\n')
      continue;
      cout << "Enter a number! ";
      }
      }*/

    cout << "Donut#1 ";

    while (i < MAX && cin >> don[i]){
        cout << "Donut#" << i+1 << " ";
        mount++;
        i++;
    }

    for(int j = 0; j < i; j++)
        sum += don[j];

    double mid = sum/mount;
    int count(0);
    cout << "Middle " << mid << endl;
    for(double r:don)
        if (r > mid)
            ++count;
    cout << "Above middle " << count << " times." << endl;
}

void exe_3(){
    char ch;
    string word;
    bool state(0);

    cout << "Please enter one of the following choices:\n";
    cout << "c) carnivore\tp) pianist\nt) tree\tg) game\n";

    while(!state){
        cin >> ch;
        switch(ch){
            case 'c':
                word = "carnivore";
                state = 1;
                break;
            case 'p':
                word = "pianist";
                state = 1;
                break;
            case 't':
                word = "tree";
                state = 1;
                break;
            case 'g':
                word = "game";
                state = 1;
                break;
            default:
                cout << "Please enter a c, p, t, or g: ";
                break;
        }
    }
    cout << "A maple is a " << word << endl;
}

void exe_4(){
    int const strsize(50);

    struct bop {
        char fullname[strsize];
        char title[strsize];
        char bopname[strsize];
        int preference;
    };

    bop mem[3] = {
        {"Victor Pelevin", "Pisatel", "Fantast", 0},
        {"Marcel Casel", "Actor", "Trahatel", 2},
        {"Dzuba", "Hromonog", "Drocher", 1}
    };

    char ch;
    //bool state(0);

    cout << "a. display by name\tb. display by title\nc. display by bopname\td. display by preference\nq. quit\n";
    cout << "Enter ur choice: ";

    while((ch = cin.get()) != 'q')
        switch(ch){
            case 'a':
                cout << mem[0].fullname << endl << mem[1].fullname << endl << mem[2].fullname << endl;
                break;
            case 'b':
                cout << mem[0].title << endl << mem[1].title << endl << mem[2].title << endl;
                break;
            case 'c':
                cout << mem[0].bopname << endl << mem[1].bopname << endl << mem[2].bopname << endl;
                break;
            case 'd':
                for(int i = 0; i < 3; i++){
                    if(mem[i].preference == 0)
                        cout << mem[i].fullname <<  endl;
                    else if (mem[i].preference == 1)
                        cout << mem[i].title << endl;
                    else
                        cout << mem[i].bopname << endl;
                }
                break;
            default:
                cout << "Enter ur choice: ";
                break;
        }
    cout << "Bye!" << endl;
}

void exe_5(){
    long digit(0);
    long balance(0);
    long sum(0);

    cout << "Enter denegka pls: ";

    cin >> digit;
    balance = digit;

    if(!cin.fail() && digit > 0){
        if (balance > 5000){
            sum = 5000 * 0;
            balance -= 5000;
        } if (balance >= 10000){
            sum += 10000 * 0.1;
            balance -= 10000;
        } if (balance >= 20000){
            sum += 20000 * 0.15;
            balance -= 20000;
        } if (balance > 0){
            sum += balance * 0.2;
        }
        cout << "Final revenue: " << sum << endl;
    } else { cout << "You not right!\n";}
}

void exe_6(){
    struct donut {
        string name;
        double money;
    };

    int count(0);
    int state(0);
    int sta_low(0);

    cout << "Enter numbers of members donuterov: ";
    cin >> count;

    donut don[count];

    if(!cin.fail() && count > 0){
        for(int i = 0; i < count; i++){
            cout << "Enter name donutera#" << i+1 << ": ";
            cin.ignore();
            getline(cin, don[i].name);
            cout << "Enter amount of donut: ";
            cin >> don[i].money;}
    } else cout << "U not right!\n";

    cout << "\nGrand Patron:\n";
    for(int j = 0; j < count; j++){
        if(don[j].money >= 10000){
            cout << don[j].name << endl;
            sta_low++;}
        else if(don[j].money < 10000 && don[j].money >= 0)
            state += 1;
        if(state == 3)
            cout << "None\n";
    }

    cout << "\nPatron:\n";
    for(int j = 0; j < count; j++){
        if(don[j].money < 10000 && don[j].money > 0)
            cout << don[j].name << endl;
    }
    if(sta_low == 3)
        cout << "None\n";
}

void exe_7(){
    string word;
    int vowel(0);
    int novowel(0);
    int other(0);
    vector<string> v;

    cout << "Enter words (q to quit): ";

    while((cin >> word) && word != "q"){
        v.push_back(word);
    }
    for(string h:v){
        if(isalpha(h[0])){
            switch(h[0]){
                case 'a':
                case 'A':
                    ++vowel;
                    break;
                case 'e':
                case 'E':
                    ++vowel;
                    break;
                case 'i':
                case 'I':
                    ++vowel;
                    break;
                case 'o':
                case 'O':
                    ++vowel;
                    break;
                case 'u':
                case 'U':
                    ++vowel;
                    break;
                default:
                    ++novowel;
            }
        } else ++other;

    } cout << vowel << " words beginning with vowels\n" << novowel << " words beginning with consonants\n" << other << " with others\n";
}

void exe_8(){
    ifstream inFile;
    inFile.open("fish.txt");
    int count(0);
    char ch;

    if(!inFile.is_open()){
        cout << "Could't open the file \n";
        cout << "Program terminator. Love this movie. \n";
        exit(1);
    }

    inFile >> ch;
    while (inFile.good()){
        ++count;
        inFile >> ch;
    }
    if(inFile.eof()){
        cout << "EOF reach!\n";
    } else if (inFile.fail())
        cout << "Input mismatch\n";
    else
        cout << "Input uknown reason\n";

    cout << count << endl;
    inFile.close();
}

void exe_9(){
    ifstream inFile;
    inFile.open("fish.txt");
    string ch;
    vector<string> v;
    int i[20] {0};
    string s[20] {"\0"};
    int j(0), jk(0);

    while((inFile >> ch) && inFile.good())
        v.push_back(ch);

    for(string g:v){
        if(isdigit(g[0])){
            i[j] = stoi(g);
            ++j;}
        if(isalpha(g[0])){
            s[jk] = g;
            ++jk;}
    }

    int k = -2;
    cout << "Grand Patron!: \n";
    for(int g:i){
        if(g != 0){
            //cout << k << " " << g << endl;
            if(g > 5000){
                cout << s[k] << " " << s[k+1] << endl;
            }
            k+=2;
        }
    }
    k = -2;
    cout << "Patron!: \n";
    for(int g:i){
        if(g != 0){
            if(g <= 5000 && g > 0 && g != 4){
                cout << s[k] << " " << s[k+1] << endl;
            }
            k+=2;
        }
    }



    if(inFile.eof()){
        cout << "\nEOF reach!\n";
    } else if (inFile.fail())
        cout << "\nInput mismatch\n";
    else
        cout << "\nInput uknown reason\n";

    inFile.close();
}
